package top.yongyan0624.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yongyan0624.common.lang.Result;
import top.yongyan0624.service.SysUserService;

/**
 * @author Yongyan
 * @description: TODO
 * @date 2021/8/15
 **/

@RestController
public class TestController extends BaseController {

    @Autowired
    private SysUserService userService;

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public Object test(){
        return Result.success(userService.list());
    }

    @GetMapping("/test/pwd")
    public Object pwd(){
        String encode = passwordEncoder.encode("123456"); //得到加密密码
        boolean ok = passwordEncoder.matches("123456", encode);//尝试将原密码和加密密码匹配
        System.out.println("匹配结果：" + ok);

        return Result.success(encode);
    }
}
